package com.kcwl.carrier.domain.factory;

import com.kcwl.carrier.domain.entity.CarrierInfo;
import com.kcwl.carrier.infrastructure.constant.CarrierConstant;
import com.kcwl.carrier.infrastructure.enums.*;
import com.kcwl.carrier.interfaces.command.CarrierApproveCommand;
import com.kcwl.ddd.application.constants.IdentityTypeEnum;
import com.kcwl.ddd.application.constants.YesNoEnum;
import com.kcwl.framework.utils.KcBeanConverter;

import java.util.Date;

/**
 * @author 刘旭超
 * @date 2022年07月13日 16:38
 * @Description
 */
public class CarrierInfoFactory {

    /**
     * 创建司机认证信息对象
     */
    public static CarrierInfo createDriverApproveInfo(CarrierApproveCommand carrierApproveCommand) {
        CarrierInfo carrierInfo = createPublicInfo(carrierApproveCommand);
        carrierInfo.setIdentityType(IdentityTypeEnum.CARRIER_DRIVER.getSubType());
        carrierInfo.setAppraisalScore(CarrierConstant.DRIVER_APPRAISAL_SCORE);
        carrierInfo.setCaptainCollaborateLimit(CarrierConstant.CAPTAIN_COLLABORATE_LIMIT);
        return carrierInfo;
    }

    /**
     * 创建车老板认证信息对象
     */
    public static CarrierInfo createCarrierBossApproveInfo(CarrierApproveCommand carrierApproveCommand) {
        CarrierInfo carrierInfo = createPublicInfo(carrierApproveCommand);
        carrierInfo.setIdentityType(IdentityTypeEnum.CARRIER_SFLTOP.getSubType());
        carrierInfo.setAppraisalScore(CarrierConstant.DRIVER_APPRAISAL_SCORE);
        return carrierInfo;
    }

    /**
     * 创建物流公司认证信息对象
     */
    public static CarrierInfo createCarrierCompanyApproveInfo(CarrierApproveCommand carrierApproveCommand) {
        CarrierInfo carrierInfo = createPublicInfo(carrierApproveCommand);
        carrierInfo.setIdentityType(IdentityTypeEnum.CARRIER_TCOM_MANAGER.getSubType());
        carrierInfo.setAppraisalScore(CarrierConstant.DRIVER_APPRAISAL_SCORE);
        return carrierInfo;
    }

    /**
     * 创建运力辅助人认证信息对象
     */
    public static CarrierInfo createCarrierAiderInfo(CarrierApproveCommand carrierApproveCommand) {
        CarrierInfo carrierInfo = createPublicInfo(carrierApproveCommand);
        carrierInfo.setIdentityType(IdentityTypeEnum.CARRIER_BRKR.getSubType());
        carrierInfo.setAppraisalScore(CarrierConstant.DRIVER_APPRAISAL_SCORE);
        carrierInfo.setAuxiliaryEnterpriseName(carrierApproveCommand.getCooperateEnterpriseName());
        carrierInfo.setAuxiliaryContent(carrierApproveCommand.getCooperateType());
        carrierInfo.setUnifiedSocialCreditCode(carrierApproveCommand.getCooperateUnifiedSocialCreditCode());
        return carrierInfo;
    }

    /**
     * 创建物流辅助服务商认证信息对象
     */
    public static CarrierInfo createCarrierAuxiliaryInfo(CarrierApproveCommand carrierApproveCommand) {
        CarrierInfo carrierInfo = createPublicInfo(carrierApproveCommand);
        carrierInfo.setSubmitTime(new Date());
        carrierInfo.setIdentityType(IdentityTypeEnum.CARRIER_TDSPR.getSubType());
        carrierInfo.setAppraisalScore(CarrierConstant.DRIVER_APPRAISAL_SCORE);
        return carrierInfo;
    }

    /**
     * 构造公共信息
     *
     * @return
     */
    public static CarrierInfo createPublicInfo(CarrierApproveCommand carrierApproveCommand) {
        CarrierInfo carrierInfo = KcBeanConverter.toBean(carrierApproveCommand, CarrierInfo.class);
        carrierInfo.setSubmitTime(new Date());
        carrierInfo.setId(carrierApproveCommand.getUserId());
        carrierInfo.setMobile(carrierApproveCommand.getMobile());
        carrierInfo.setName(carrierApproveCommand.getRealName());
        carrierInfo.setIdcardNo(carrierApproveCommand.getIdCardNo());
        carrierInfo.setIdcardPic(carrierApproveCommand.getIdCardFront());
        carrierInfo.setAuthenticationStatus(CarrierAuthStatusEnum.WAITING.getCode());
        carrierInfo.setIdcardReversePic(carrierApproveCommand.getIdCardBehind());
        carrierInfo.setCancer(YesNoEnum.NAY.getValue());
        carrierInfo.setUserSource(UserSourceEnum.ONESELF.getCode());
        carrierInfo.setIdcardStartTime(carrierApproveCommand.getIdCardStartTime());
        carrierInfo.setIdcardEndTime(carrierApproveCommand.getIdCardEndTime());
        carrierInfo.setIdentifyStatus(IdentifyStatusEnum.WAITING.getCode());
        carrierInfo.setBirthDate(carrierApproveCommand.getBirthday());
        carrierInfo.setPlatformNo(carrierApproveCommand.getPlatformNo());
        carrierInfo.setIdentityChangeCount(0);
        carrierInfo.setRegisterType(1);
        carrierInfo.setAddress(carrierApproveCommand.getIdCardAddress());
        return carrierInfo;
    }
}
